﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace nGSO
{
    /// <summary>
    /// Agent choses one with probability proptional to luminescence level of neighbours
    /// </summary>
    public class MaximumProbabilitySelector : INeighbourSelector
    {
        public Agent GetAgentToMoveToward(Agent forAgent)
        {
            Dictionary<Agent, double> neighborsProb = new Dictionary<Agent, double>();
            double neighborLuceferinSum = 0;

            foreach (Agent neighbor in forAgent.Neighbors)
            {
                neighborLuceferinSum += neighbor.Luciferin - forAgent.Luciferin;
            }

            foreach (var neighbour in forAgent.Neighbors)
            {
                double prob = (neighbour.Luciferin - forAgent.Luciferin) / neighborLuceferinSum;
                neighborsProb.Add(neighbour, prob);
            }

            return neighborsProb.OrderByDescending(s => s.Value).First().Key;
        }
    }
}
